<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-form ref="form" :model="change_certificate" :rules="rules" label-width="100px" id="mvcfm">
          <el-button @click="addChangeSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
          <el-button @click="gotoPage('/mes/certificate/ChangeInformation?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
          <div class="form-unit">
            <span class="mvc-title-left"> 增加变更 </span>
          </div>
          <div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="认证类型" prop="setup_id">
                  <el-select style='width:100%' v-model="change_certificate.setup_id" @change="list_s_setup">
                    <el-option label="－－无－－" value='' />
                    <el-option v-for="dict in s_setup" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="证书类型" prop="certificate_type">
                  <el-select style='width:100%' v-model="change_certificate.certificate_type" @change="list_s_type">
                    <el-option label="－－无－－" value='' />
                    <el-option v-for="dict in s_type" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="发证日期" prop="issue_date">
                  <el-date-picker v-model="change_certificate.issue_date" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="证书有效期" prop="validity_date">
                  <el-date-picker v-model="change_certificate.validity_date" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="50">
                <el-form-item label="申请人" prop="">
                  {{change_certificate.applicant_client}}
                  <el-button @click="popSelectionSupply('','applicant_client')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="50">
                <el-form-item label="制造商" prop="">
                  {{change_certificate.production_plant}}
                  <el-button @click="popSelectionSupply('','production_plant')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="生产厂" prop="">
                  {{change_certificate.engin_client_id}}
                  <el-button @click="popSelectionSupply('','engin_client_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="发证机构" prop="">
                  {{change_certificate.issue_client_id}}
                  <el-button @click="popSelectionSupply('','issue_client_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="持证人" prop="">
                  {{change_certificate.cardholder_client_id}}
                  <el-button @click="popSelectionSupply('','cardholder_client_id')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="证书变更状态" prop="chang_certificate_state">
                  <el-radio-group v-model="change_certificate.chang_certificate_state">
                    <el-radio-button :label="1">有效</el-radio-button>
                    <el-radio-button :label="2">无效</el-radio-button>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="上传证书文件" prop="">
                  <input type=file />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'变更信息'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="SelectionSupplyVisible" append-to-body>
      <SelectionSupply v-if="SelectionSupplyVisible" ref="SelectionSupply" :popparams="popparams"> </SelectionSupply>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import SelectionSupply from "@/views/mes/certificate/SelectionSupply";
  export default {
    name: 'AddChange',
    components: {
      SelectionSupply,
    },
    props: ['popparams'],
    data() {
      return {
        SelectionSupplyVisible: false,
        SelectionSupplyValue: null,
        SelectionSupplyDesc: null,
        vueparams: this.getVUEParams(""),
        change_certificate: {
          setup_id: null,
          certificate_type: null,
          issue_date: null,
          validity_date: null,
          applicant_client: null,
          production_plant: null,
          engin_client_id: null,
          issue_client_id: null,
          cardholder_client_id: null,
          chang_certificate_state: null,
        },
        s_setup: [],
        s_type: [],
        loading: false,
        Container: null,
        rules: {
          setup_id: [{
            required: true,
            message: "认证类型不能为空",
            trigger: 'blur',
          }],
          certificate_type: [{
            required: true,
            message: "证书类型不能为空",
            trigger: 'blur',
          }],
          issue_date: [{
            required: true,
            message: "发证日期不能为空",
            trigger: 'blur',
          }],
          validity_date: [{
            required: true,
            message: "证书有效期不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "018E412E935E4B3EB6DF631BB3B46A50",
        name: "客户右菜单类型",
        selected: "变更信息"
      }, 'Container', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/addChange?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      addChangeSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/certificate/CertificateAction/addChangeSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/certificate/ChangeDet/changeDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      list_s_setup(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/ajaxChange?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "certificate_type",
            setup_id: value
          }
        }).then(data => {
          this.$set(this.change_certificate, 'certificate_type', '');
          this.s_type = data['certificate_type'];
        })
      },
      list_s_type(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/ajaxChange?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "",
            certificate_type: value
          }
        }).then(data => {
          this.$set(this.change_certificate, '', '');
          this.$set(this.change_certificate, '', '');
          this.$set(this.change_certificate, '', '');
          this.$set(this.change_certificate, '', '');
        })
      },
      popSelectionSupply(desc, value) {
        this.SelectionSupplyVisible = true;
        this.SelectionSupplyDesc = desc;
        this.SelectionSupplyValue = value;
      },
      closeSelectionSupply(value, desc) {
        this.SelectionSupplyVisible = false;
        this.$set(this.change_certificate, this.SelectionSupplyDesc, desc);
        this.$set(this.change_certificate, this.SelectionSupplyValue, value);
      },
    },
  }
</script>
